package org.pblue.tumblarity.view;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.pblue.tumblarity.controller.EditBlog;


@SuppressWarnings("serial")
public class DefaultView extends HttpServlet {
  
  public static final String TEMPLATE = "/index.jsp";

  @Override
  protected void service(HttpServletRequest pRequest, HttpServletResponse pResponse) throws ServletException, IOException {
    HttpSession session = pRequest.getSession();
    
    pRequest.setAttribute(EditBlog.ATTR_EMAIL, session.getAttribute(EditBlog.ATTR_EMAIL));
    pRequest.setAttribute(EditBlog.ATTR_TUMBLELOG_NAME, session.getAttribute(EditBlog.ATTR_TUMBLELOG_NAME));
    pRequest.setAttribute(EditBlog.ATTR_ERRORS, session.getAttribute(EditBlog.ATTR_ERRORS));
    pRequest.setAttribute(EditBlog.ATTR_MESSAGE, session.getAttribute(EditBlog.ATTR_MESSAGE));
    
    session.removeAttribute(EditBlog.ATTR_EMAIL);
    session.removeAttribute(EditBlog.ATTR_TUMBLELOG_NAME);
    session.removeAttribute(EditBlog.ATTR_ERRORS);
    session.removeAttribute(EditBlog.ATTR_MESSAGE);
    
    RequestDispatcher rd = pRequest.getRequestDispatcher(TEMPLATE);
    rd.forward(pRequest, pResponse);
  } 

}
